home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 317 / asmsrc / xmalloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-20  |  1.7 KB  |  62 lines

  1. /* xmalloc.c - get memory or bust */
  2.  
  3. /* Copyright (C) 1987 Free Software Foundation, Inc.
  4.  
  5. This file is part of Gas, the GNU Assembler.
  6.  
  7. The GNU assembler is distributed in the hope that it will be
  8. useful, but WITHOUT ANY WARRANTY.  No author or distributor
  9. accepts responsibility to anyone for the consequences of using it
  10. or for whether it serves any particular purpose or works at all,
  11. unless he says so in writing.  Refer to the GNU Assembler General
  12. Public License for full details.
  13.  
  14. Everyone is granted permission to copy, modify and redistribute
  15. the GNU Assembler, but only under the conditions described in the
  16. GNU Assembler General Public License.  A copy of this license is
  17. supposed to have been given to you along with the GNU Assembler
  18. so you can know your rights and responsibilities.  It should be
  19. in a file named COPYING.  Among other things, the copyright
  20. notice and this notice must be preserved on all copies.  */
  21.  
  22.  
  23. #ifdef    DOCUMENTATION
  24.  
  25. NAME
  26.     xmalloc() - get memory or bust
  27. INDEX
  28.     xmalloc() uses malloc()
  29.  
  30. SYNOPSIS
  31.     char *    my_memory;
  32.  
  33.     my_memory = xmalloc(42); /* my_memory gets address of 42 chars */
  34.  
  35. DESCRIPTION
  36.  
  37.     Use xmalloc() as an "error-free" malloc(). It does almost the same job.
  38.     When it can't honour your request for memory it BOMBS your program
  39.     with a "virtual memory exceeded" message. Malloc() returns NULL and
  40.     doesn't bomb your program.
  41.  
  42. SEE ALSO
  43.     malloc()
  44.  
  45. #endif                /* #ifdef DOCUMENTATION */
  46.  
  47. char * xmalloc(n)
  48.      long n;
  49. {
  50.   char *    retval;
  51.   char *    malloc();
  52.   void    error();
  53.  
  54.   if ( ! (retval = malloc ((unsigned)n)) )
  55.     {
  56.       error("virtual memory exceeded");
  57.     }
  58.   return (retval);
  59. }
  60.  
  61. /* end: xmalloc.c */
  62.